﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace 深入浅出WPF_Chapter8路由事件
{
    /// <summary>
    /// Interaction logic for Sample3.xaml
    /// </summary>
    public partial class Sample3 : Window
    {
        public Sample3()
        {
            InitializeComponent();

            //为主窗体添加对Button.Click事件的侦听
            this.AddHandler(Button.ClickEvent,new RoutedEventHandler(this.Button_Click));
        }

        //路由事件处理器
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string strOriginalSource = string.Format("VisualTree start point:{0},type is {1}", (e.OriginalSource as FrameworkElement).Name, e.OriginalSource.GetType().Name);
            string strSource = string.Format("LogicalTree start point:{0},type is {1}", (e.Source as FrameworkElement).Name, e.Source.GetType().Name);
            MessageBox.Show(strOriginalSource + "\r\n" + strSource);
        }
    }
}
